﻿using System;
using System.Collections.Generic;
using System.Web.UI.WebControls;
using Yipusoft.Common.BLL;
using Yipusoft.Common.Model;
using Yipusoft.Evaluate.BLL;
using Yipusoft.Evaluate.Model;

public partial class Evaluate_AwardListD : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Yipusoft.Account.BLL.User.HasPermission(Context.User.Identity.Name, "320501"))
        {
            Response.Write("<script>alert('没有权限！');history.back(0);</script>");
        }
        if (!IsPostBack)
        {
            BindYearList();
            BindGrid();
        }
    }
    private void BindYearList()
    {
        for (int i = 2008; i <= 2050; i++)
        {
            ListItem li = new ListItem();
            li.Text = i.ToString() + "年";
            li.Value = i.ToString();
            YearList.Items.Add(li);
        }
        YearList.SelectedValue = DateTime.Now.Year.ToString();
    }
    private void BindGrid()
    {
        string DepartmentID = Yipusoft.Account.BLL.User.GetUser(User.Identity.Name).DepartmentID.Substring(0, 6) + "0";
        List<AwardInfo> Awards = Award.GetList("year(Awarddate)=" + YearList.SelectedValue + " And DepartmentID='" + DepartmentID + "' and Flag=" + rbType.SelectedValue + " order by Awarddate");
        UserGrid.DataSource = Awards;
        UserGrid.DataBind();
    }
    protected void UserGrid_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label ID = (Label)e.Row.FindControl("ID");
            ID.Text = (e.Row.RowIndex + 1).ToString();
            //当鼠标放上去的时候 先保存当前行的背景颜色 并给附一颜色 
            e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#F5F5F5',this.style.fontWeight='';");
            //当鼠标离开的时候 将背景颜色还原的以前的颜色 
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor,this.style.fontWeight='';");
            LinkButton ButtonDelete = (LinkButton)e.Row.FindControl("ButtonDelete");
            ButtonDelete.Attributes.Add("onclick", "return confirm('确定删除吗？')");
        }
    }
    protected void UserGrid_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        int AwardId = (int)UserGrid.DataKeys[e.RowIndex].Value;
        Award.Delete(AwardId);

        EventLogInfo log = new EventLogInfo();
        log.EventTime = DateTime.Now;
        log.EventType = 1;
        log.EventData = "删除工作奖惩项目";
        log.ItemID = AwardId.ToString();
        log.ItemName = "Awards";
        log.ItemFullUrl = "AwardList.aspx";
        log.CreatedBy = Context.User.Identity.Name;
        log.CreatedTime = DateTime.Now;
        log.UserIP = Request.UserHostAddress;
        EventLog.Insert(log);

        BindGrid();
    }
    protected void YearList_SelectedIndexChanged(object sender, EventArgs e)
    {
        BindGrid();
    }
    protected void rbType_SelectedIndexChanged(object sender, EventArgs e)
    {
        BindGrid();
    }
}
